package jykim;

import java.util.Iterator;
import java.util.TreeSet;

public class Lotto {
	
	private int[] lottoNum;
	TreeSet<Integer> ts = new TreeSet<Integer>();
	
	public Lotto(){
		lottoNum = new int[6];
	}
	
	
	public void execute(){
		
		while(!isCheck()){
			this.selectNum();
		}
		
		for (int i = 0; i < lottoNum.length; i++) {
			ts.add(lottoNum[i]);
		}
		
		print();
	}
	
	
	public void selectNum(){
		for (int i = 0; i < lottoNum.length; i++) {
			lottoNum[i] = (int)(Math.random()*45 + 1);
		}
		
	}
	
	
	public void print(){
		
		Iterator<Integer> it = ts.iterator();
		
		while(it.hasNext()){
			System.out.print(it.next() + "\t");
		}
	}
	
	
	public boolean isCheck(){
		
		boolean isS = true;
		
		for (int i = 0; i < lottoNum.length; i++) {
			for (int j = 1; (i+j) < lottoNum.length; j++) {
				if(lottoNum[i]==lottoNum[i+j]){
					isS = false;
				}
			}
		}
		return isS;
	}
}
